<?php
require_once 'DBUtils.php';
function getAllContient() {
	$sql = "select * from contient";
	$dbUtil = new DBUtils();
	$res = $dbUtil->queryRows($sql);
	return $res;
}

function getCountryByContient($contientId, $letter) {
	$sql = "select * from country where contient_id =".$contientId;
	
	if(!empty($letter)) {
		$sql = $sql." and first_character='".$letter."'";
	}
	$dbUtil = new DBUtils();
	$res = $dbUtil -> queryRows($sql);
	return $res;
}

function getCountryById($countryId) {
	$sql = "select * from country where id=".$countryId;
	$dbUtil = new DBUtils();
	$res = $dbUtil -> queryObj($sql);
	return $res;
}

function getAllCountry() {
	$sql = "select * from country order by first_character";
	$dbUtil = new DBUtils();
	$res = $dbUtil -> queryRows($sql);
	return $res;
}

function getProductByCountry($countryId) {
	$sql = "select * from product where country_id=".$countryId;
	
	$dbUtil = new DBUtils();
	$res = $dbUtil -> queryRows($sql);
	return $res;
}

function getSpecialContient() {
	$sql = "select distinct d.* from special_offer a 
		left join product b on a.product_id = b.id 
		left join country c on b.country_id=c.id 
		left join contient d on c.contient_id=d.id";
	$dbUtil = new DBUtils();
	$res = $dbUtil -> queryRows($sql);
	return $res;
}

function getSpecialByContient($contientId) {
	$sql = "select b.*,a.original_price from special_offer a 
		left join product b on a.product_id = b.id 
		left join country c on b.country_id=c.id 
		left join contient d on c.contient_id=d.id where contient_id=$contientId";
	$dbUtil = new DBUtils();
	$res = $dbUtil -> queryRows($sql);
	return $res;
}

function getFirstPickCountry() {
	$sql = "select b.*,a.price,a.img image from pick_country a 
		left join country b on a.country_id=b.id 
		where show_first=1 order by a.sort_num limit 4";
	$dbUtil = new DBUtils();
	$res = $dbUtil -> queryRows($sql);
	return $res;
}

function getSecondPickCountry() {
	$sql = "select b.*,a.price,a.img image from pick_country a
		left join country b on a.country_id=b.id
		where show_first<>1 limit 12";
	$dbUtil = new DBUtils();
	$res = $dbUtil -> queryRows($sql);
	return $res;
}

function getHotCountry() {
	$sql = "select b.*,a.img image,a.tip from hot_country a 
		left join country b on a.country_id=b.id";
	$dbUtil = new DBUtils();
	$res = $dbUtil -> queryRows($sql);
	return $res;
}

function getBySQL($sql) {
	$dbUtil = new DBUtils();
	$res = $dbUtil -> queryRows($sql);
	return $res;
}

function getProductById($pid) {
	$sql = "select a.*, b.name country_name from product a 
		left join country b on a.country_id=b.id
		where a.id=".$pid;
	$dbUtil = new DBUtils();
	$res = $dbUtil -> queryObj($sql);
	return $res;
}

function getVisaType($pid) {
	$sql = "select * from visa_type where product_id=".$pid;
	$dbUtil = new DBUtils();
	$res = $dbUtil -> queryRows($sql);
	return $res;
}

function getPersonType($pid) {
	$sql = "select * from person_type where person_type in (
		select distinct(person_type) from visa_material 
		where product_id=$pid)";
	$dbUtil = new DBUtils();
	$res = $dbUtil -> queryRows($sql);
	return $res;
}

function getMaterial($pid, $personType) {
	$sql = "select * from visa_material where product_id=$pid and person_type=$personType";
	$dbUtil = new DBUtils();
	$res = $dbUtil -> queryRows($sql);
	return $res;
}

function saveMsg($name, $phone, $content) {
	$sql = "insert into msg(name,phone,content) values('$name', '$phone', '$content')";
	$dbUtil = new DBUtils();
	$dbUtil -> update($sql);
}






